

import java.util.Calendar;
import java.sql.*;
import javax.swing.JOptionPane;

public class Registration {
    public int studentID;
    public int year;
    public Calendar dateSubmitted;
    public boolean isComplete;
    public boolean onCampusTerm1;
    public boolean onCampusTerm2;
    public boolean onCampusTerm3;
    public String signature;

    
    private Connection connect;
    
    /*
    public Registration(int studentID, int year) {
        this.studentID = studentID;
        this.year = year;
    }
     * 
     */
    
    public Registration(int studentID, int year, Connection connect){
        this.connect = connect;
        this.studentID = studentID;
        this.year = year;
        loadFromDB();
    }
    
    
    private void loadFromDB(){
        try {
            String loadQuery = "select * from registration where studentID = ? AND year = ?";
            PreparedStatement loadStmt = connect.prepareStatement(loadQuery);
            loadStmt.setInt(1, studentID);
            loadStmt.setInt(2, year);
            ResultSet registrationInfo = loadStmt.executeQuery();
            if(registrationInfo.next()){
                dateSubmitted = Calendar.getInstance();
                dateSubmitted.setTimeInMillis(registrationInfo.getTimestamp("dateSubmitted").getTime());
                isComplete = registrationInfo.getBoolean("isComplete");
                onCampusTerm1 = registrationInfo.getBoolean("onCampusTerm1");
                onCampusTerm2 = registrationInfo.getBoolean("onCampusTerm2");
                onCampusTerm3 = registrationInfo.getBoolean("onCampusTerm3");
                signature = registrationInfo.getString("signature");
            }
            
            
        } catch (Exception ex){
            JOptionPane.showMessageDialog(null,
                    "Unable to load registration from database.");
            
        }
        
    }
    
    
    
    
}
